package com.mvc.cms.dao.assist.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.mvc.cms.dao.assist.DataDictionaryDao;
import com.mvc.cms.entity.assist.DataDictionary;
import com.mvc.common.hibernate3.Finder;
import com.mvc.common.hibernate3.HibernateBaseDao;
import com.mvc.common.page.Pagination;

/** DataDictionaryDaoImpl概要说明：
 * <br>@author 彭粟
 */
@Repository
public class DataDictionaryDaoImpl extends 
        HibernateBaseDao<DataDictionary,Integer> implements DataDictionaryDao {

	@Override
	protected Class getEntityClass() {
		// TODO Auto-generated method stub
		return DataDictionary.class;
	}

	public DataDictionary delte(Integer id) {
		DataDictionary bean = get(id);
		if(bean != null){
			getSession().delete(bean);
		}
		return bean;
	}

	public DataDictionary getInfoById(Integer id) {
		return (DataDictionary) getSession().get(DataDictionary.class, id);
	}

	public DataDictionary save(DataDictionary bean) {
		
		getSession().saveOrUpdate(bean);
		return bean;
	}

	public Pagination getPage(Integer type, Integer status,int page,int pageSize) {
		Finder f = Finder.create("from DataDictionary bean where 1=1");
		if (type != null) {
			f.append(" and bean.type=:type");
			f.setParam("type", type);
		}
		if (status != null) {
			f.append(" and bean.status =:status");
			f.setParam("status", status);
		}
		 f.append(" order by bean.id desc");
		return find(f, page, pageSize);
	}

	public List<DataDictionary> list(int type) {
		Finder f = Finder.create("from DataDictionary bean where 1=1");
		if(type >0) {
			f.append(" and bean.type=:type");
			f.setParam("type", type);
		}
		f.append(" and bean.isUse = 1");
		return find(f);
	}
}
